<template>
    <base-breadcrumb>
        <a-spin :spinning="loading">
        <a-tabs type="card" v-model:activeKey="activeKey" style="background-color: #fff">
            <template v-for="item in tabs">
                <a-tab-pane :key="item.key" :tab="item.name" v-if="item.show">
                </a-tab-pane>
            </template>

        </a-tabs>
        <div style="background-color: #fff">
            <Component
                    :is="activeKey"
                    :form="form"
                    :row="form"
            ></Component>
            <div class="page-btn-right-top">
                <a-button @click="$router.back()">关闭</a-button>
            </div>
        </div>
        </a-spin>
    </base-breadcrumb>
</template>

<script>
    import baseInfo from "./components/baseInfo"
    import secondInfo from "./components/secondInfo"
    import replyinfo from "./components/replyinfo"
    import schemeDisclosure from "./components/schemeDisclosure"
    import technicalDisclosure from "./components/technicalDisclosure"
    import putIntoEffect from "./components/putIntoEffect"
    import checkInfo from "./components/checkInfo"
    import acceptInfo from "./components/acceptInfo"
    import replenishInfo from './components/replenishInfo'
    import {  getDetails,getConstructionProgramHistoryById} from '@/api/technical/approval'
  export default {
    name: 'a' + new Date().getTime(),
    components: {
      baseInfo,
      secondInfo,
      replyinfo,
      schemeDisclosure,
      technicalDisclosure,
      putIntoEffect,
      checkInfo,
      acceptInfo,
      replenishInfo
    },
    data() {
      let that = this
      return {
        activeKey: 'baseInfo',
        form: {
          changeForm: {
            changeFileInfo: {}
          }
        },
        tabs: [
          {
            name: '基本信息',
            key: 'baseInfo',
            show: true
          },
          {
            name: '二次报审',
            key: 'secondInfo',
            show: false
          },
          {
            name: '回复信息',
            key: 'replyinfo',
            show: !!that.$route.query.replyId
          },
          {
            name: '方案交底信息',
            key: 'schemeDisclosure',
            show: !!that.$route.query.confessAuditStatusId
          },
          {
            name: '技术交底信息',
            key: 'technicalDisclosure',
            show: !!that.$route.query.technologyStatusId
          },
          {
            name: '实施信息',
            key: 'putIntoEffect',
            show: true
          },
          {
            name: '复核信息',
            key: 'checkInfo',
            show: !!that.$route.query.reAuditId
          },
          // {
          //   name: '验收信息',
          //   key: 'acceptInfo'
          // },
          {
            name: '补充信息',
            key: 'replenishInfo',
            show: true
          },
        ],
        id: '',
        historicalData: false,
        loading: false
      }
    },
    created() {
      this.historicalData = this.$route.query.historicalData || false;   //是否是点击历史版本查看历史数据
      this.id = this.$route.query.id || '';
      this.getDetails()
    },
    methods: {
      getDetails() {
        if (this.id) {
          this.loading = true
          let api = this.historicalData? getConstructionProgramHistoryById : getDetails;
          api({ id: this.id }).then((res) => {
            this.form = {
              ...this.form,
              ...res.data
            }
            this.loading = false
            if(this.form.programTypeName ==='A') {
                this.tabs[1].show = true
            }
            this.form.programTypeId = res.data.programTypeId
            this.form.planSelection = res.data.planSelectionId
            this.form.whetherMajorExpense = res.data.whetherMajorExpense === 'true' ? true : false
            this.form.whetherProfessionalSubcontracting = res.data.whetherProfessionalSubcontracting === 'true' ? true : false
            this.goodBusDTO = this.form?.goodBusDTO;
            this.form.dangerDangerDTOS = res.data.dangerDangerDTOS || []
            this.form.newFileInfoVOS['4'] = res.data.newFileInfoVOS && res.data.newFileInfoVOS['4'] || [];
            this.$nextTick(() => {
              this.form.projectId = res.data.projectId
              this.$nextTick(() => {
                this.form.compiler = res.data.compiler
              })
            })

            if (res.data.twoReportBusinessVO) {
              this.form.changeForm = res.data.twoReportBusinessVO
              this.form.changeForm.changeFileInfo = res.data.twoReportBusinessVO.fileInfoVOS
            }
            this.form.changeFileInfo2 = res.data.newFileInfoVOS
          })
        }
      },
    }
  }
</script>

<style scoped>

</style>